<template>
	<!-- 入库检任务清单模态框 -->
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="8">
			<p-form-item label="送检单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'inspectBillno', validatorRules.inspectBillno]" placeholder="请输入送检单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="产品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="mes-quality"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="mid,mcode,mname,sprc,mexplain"
						dest-fields="mid,mcode,mname,sprc,mexplain"
						code="mes_cctv_plan_mcode"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入产品名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="产品属性" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mtype', validatorRules.mtype]" placeholder="请输入产品属性"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="线体" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['linename', validatorRules.linename]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename"
						dest-fields="lineid,lineno,linename"
						code="line_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'lineno', validatorRules.lineno]" placeholder="请输入线体编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="生产工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'productionno', validatorRules.productionno]" placeholder="请输入生产工单"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="工序工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'processbillno', validatorRules.processbillno]" placeholder="请输入工序工单"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="操作时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择操作时间" v-decorator="[ 'operationDt', validatorRules.operationDt]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="送检人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-select-user-by-dep v-decorator="['sendInspecter', validatorRules.sendInspecter]" :trigger-change="true"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="送检时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择送检时间" v-decorator="[ 'sendInspectTime', validatorRules.sendInspectTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="待检数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'waitInspectNumber', validatorRules.waitInspectNumber]" placeholder="请输入待检数量" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="管控方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['controlsType', validatorRules.controlsType]" :trigger-change="true" dictCode="mes_controls_type" placeholder="请选择管控方式"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="品号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'screeningItem', validatorRules.screeningItem]" placeholder="请输入品号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="工单" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'screeningWorkOrder', validatorRules.screeningWorkOrder]" placeholder="请输入工单"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="线体" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'screeningLine', validatorRules.screeningLine]" placeholder="请输入线体"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="线板" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'screeningLineBoard', validatorRules.screeningLineBoard]" placeholder="请输入线板"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'screeningSn', validatorRules.screeningSn]" placeholder="请输入SN"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="剩余检验时长" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'remainingInspectTime', validatorRules.remainingInspectTime]" placeholder="请输入剩余检验时长" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="MRB" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-switch  placeholder="String" v-decorator="['mrb']" field="mrb" dictCode="" @callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="入库库位" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'inbankIndex', validatorRules.inbankIndex]" placeholder="请输入入库库位"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="入库仓库" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'inbankBank', validatorRules.inbankBank]" placeholder="请输入入库仓库"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction, putAction, api } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import fSwitch from '@/components/switch'
  import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesQcIntoWarehouseInspectTaskModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JSelectUserByDep,
      JDictSelectTag,
      fSwitch,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 1200,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        inspectBillno:{},
        mcode:{rules: [{ required: false, message: '请输入产品编码!' }]},
        mname:{rules: [{ required: false, message: '请输入产品名称!' }]},
        mtype:{},
        linename:{rules: [{ required: false, message: '请输入线体!' }]},
        lineno:{},
        productionno:{rules: [{ required: false, message: '请输入生产工单!' }]},
        processbillno:{rules: [{ required: false, message: '请输入工序工单!' }]},
        operationDt:{rules: [{ required: false, message: '请输入操作时间!' }]},
        sendInspecter:{rules: [{ required: false, message: '请输入送检人!' }]},
        sendInspectTime:{rules: [{ required: false, message: '请输入送检时间!' }]},
        waitInspectNumber:{rules: [{ required: false, message: '请输入待检数量!' }]},
        controlsType:{rules: [{ required: false, message: '请输入管控方式!' }]},
        screeningItem:{},
        screeningWorkOrder:{},
        screeningLine:{},
        screeningLineBoard:{},
        screeningSn:{},
        remainingInspectTime:{rules: [{ required: false, message: '请输入剩余检验时长!' }]},
        mrb:{rules: [{ required: false, message: '请输入MRB!' }]},
        inbankIndex:{},
        inbankBank:{},
        },
        url: {
          add: '/mes-quality/mesQcIntoWarehouseInspectTask/add',
          edit: '/mes-quality/mesQcIntoWarehouseInspectTask/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
        this.getRuleCodeValue();
      },
      getRuleCodeValue() {
        let param = {
          commonFormData: this.model,
          rules: [
            {"ruleCode": "mes_into_warehouse_rule", "columnName": "inspectBillno"},
            ]
        }

        putAction(api.ruleBaseURL, param).then(res => {
          // 执行成功，获取返回的值，并赋到页面上
          if (res.success) {
            console.log("生成的编码：" + res.data)
            const item = res.data;
            this.form.setFieldsValue(pick(item, Object.keys(item)))
          }
        })
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','remark','inspectBillno','mcode','mname','mtype','linename','lineno','productionno','processbillno','operationDt','sendInspecter','sendInspectTime','waitInspectNumber','controlsType','screeningItem','screeningWorkOrder','screeningLine','screeningLineBoard','screeningSn','remainingInspectTime','inspectAmount','inspectStatus','inspectResult','mrb','inbankIndex','inbankBank'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','remark','inspectBillno','mcode','mname','mtype','linename','lineno','productionno','processbillno','operationDt','sendInspecter','sendInspectTime','waitInspectNumber','controlsType','screeningItem','screeningWorkOrder','screeningLine','screeningLineBoard','screeningSn','remainingInspectTime','inspectAmount','inspectStatus','inspectResult','mrb','inbankIndex','inbankBank'))
      },

      
    }
  }
</script>
